<template>
	<view>
		<u-tabbar :value="navBar" @change="changeHandler" :fixed="true" :placeholder="true" :safeAreaInsetBottom="true"
			activeColor="#0f559f">
			<u-tabbar-item text="首页">
				<u-icon slot="active-icon" color="#0f559f" name="home-fill" class="icon-setting" size="45"></u-icon>
				<u-icon slot="inactive-icon" color="#d3d3d3" name="home-fill" class="icon-setting" size="45"></u-icon>
			</u-tabbar-item>
			<u-tabbar-item text="点单">
				<u-icon slot="active-icon" color="#0f559f" name="car-fill" class="icon-setting" size="45"></u-icon>
				<u-icon slot="inactive-icon" color="#d3d3d3" name="car-fill" class="icon-setting" size="45"></u-icon>
			</u-tabbar-item>
			<u-tabbar-item text="订单">
				<u-icon slot="active-icon" color="#0f559f" name="file-text-fill" class="icon-setting"
					size="45"></u-icon>
				<u-icon slot="inactive-icon" color="#d3d3d3" name="file-text-fill" class="icon-setting"
					size="45"></u-icon>
			</u-tabbar-item>
			<u-tabbar-item text="我的">
				<u-icon slot="active-icon" color="#0f559f" name="account-fill" class="icon-setting" size="45"></u-icon>
				<u-icon slot="inactive-icon" color="#d3d3d3" name="account-fill" class="icon-setting"
					size="45"></u-icon>
			</u-tabbar-item>
		</u-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navBar: 0,
			};
		},
		created() {
			let pages = getCurrentPages(); // 获取当前页面栈
			let currentPage = pages[pages.length - 1]; // 获取当前页面实例
			let currentPagePath = currentPage.route;
			if (currentPagePath == 'pages/views/home/index') {
				this.navBar = 0
			} else if (currentPagePath == 'pages/views/buy/buy') {
				this.navBar = 1
			} else if (currentPagePath == 'pages/views/order/order') {
				this.navBar = 2
			} else if (currentPagePath == 'pages/views/user-center/user-center') {
				this.navBar = 3
			}
		},
		methods: {
			changeHandler(value) {
				this.navBar = value
				let url = ''
				if (value == 0) {
					url = '/pages/views/home/index'
				} else if (value == 1) {
					url = '/pages/views/buy/buy'
				} else if (value == 2) {
					url = '/pages/views/order/order'
				} else if (value == 3) {
					url = '/pages/views/user-center/user-center'
				}
				uni.reLaunch({
					url: url
				});
			},
		},
	}
</script>

<style lang="scss" scoped>
	.icon-setting {
		width: 40rpx;
		height: 40rpx;
	}
</style>